from bs4 import BeautifulSoup

# 示例HTML数据
html_data = """ vvvvc v 
   <tr><td class='desktop-only item '>173334</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1397'>F</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=173334 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>9 ms</div></td><td><a target=_self href=showsource.php?id=173334>C</a></td><td class='desktop-only item '>705 bytes</td><td>2025-01-01 14:46:34</td></tr>
<tr><td class='desktop-only item '>164487</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1403'>G</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=164487 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>5 ms</div></td><td><a target=_self href=showsource.php?id=164487>C</a></td><td class='desktop-only item '>845 bytes</td><td>2024-12-23 00:29:18</td></tr>
<tr><td class='desktop-only item '>164484</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1529'>H</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=164484 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>4 ms</div></td><td><a target=_self href=showsource.php?id=164484>C</a></td><td class='desktop-only item '>819 bytes</td><td>2024-12-23 00:25:31</td></tr>
<tr><td class='desktop-only item '>164478</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1338'>C</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=164478 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>9 ms</div></td><td><a target=_self href=showsource.php?id=164478>C</a></td><td class='desktop-only item '>1052 bytes</td><td>2024-12-23 00:05:28</td></tr>
<tr><td class='desktop-only item '>164477</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1338'>C</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=11></span><a href=ceinfo.php?sid=164477 class='label label-warning' title='编译错误，请点击后获得编译器的详细输出'>编译错误</a></td><td><div id=center>0 KiB</div></td><td><div id=center>0 ms</div></td><td><a target=_self href=showsource.php?id=164477>C</a></td><td class='desktop-only item '>1112 bytes</td><td>2024-12-23 00:05:13</td></tr>
<tr><td class='desktop-only item '>163786</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1338'>C</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=163786 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>10 ms</div></td><td><a target=_self href=showsource.php?id=163786>C</a></td><td class='desktop-only item '>1764 bytes</td><td>2024-12-22 12:58:04</td></tr>
<tr><td class='desktop-only item '>163733</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1338'>C</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=5></span><a href=reinfo.php?sid=163733 class='label label-danger' title='答案基本正确，但是格式不对。'>格式错误 得分0</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>8 ms</div></td><td><a target=_self href=showsource.php?id=163733>C</a></td><td class='desktop-only item '>1095 bytes</td><td>2024-12-22 11:35:48</td></tr>
<tr><td class='desktop-only item '>150806</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1277'>B</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=150806 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>7 ms</div></td><td><a target=_self href=showsource.php?id=150806>C</a></td><td class='desktop-only item '>798 bytes</td><td>2024-12-10 08:53:25</td></tr>
<tr><td class='desktop-only item '>150797</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1277'>B</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=9></span><a href=reinfo.php?sid=150797 class='label label-warning' title='输出超过限制，你的输出比正确答案长了两倍，一定是哪里弄错了'>输出超限 得分0</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>43 ms</div></td><td><a target=_self href=showsource.php?id=150797>C</a></td><td class='desktop-only item '>642 bytes</td><td>2024-12-10 08:48:51</td></tr>
<tr><td class='desktop-only item '>150789</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1277'>B</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=11></span><a href=ceinfo.php?sid=150789 class='label label-warning' title='编译错误，请点击后获得编译器的详细输出'>编译错误</a></td><td><div id=center>0 KiB</div></td><td><div id=center>0 ms</div></td><td><a target=_self href=showsource.php?id=150789>C</a></td><td class='desktop-only item '>646 bytes</td><td>2024-12-10 08:46:40</td></tr>
<tr><td class='desktop-only item '>138897</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1212'>A</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=138897 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>4 ms</div></td><td><a target=_self href=showsource.php?id=138897>C</a></td><td class='desktop-only item '>564 bytes</td><td>2024-11-30 21:30:14</td></tr>
<tr><td class='desktop-only item '>138796</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1212'>A</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=138796 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1252 KiB</div></td><td><div id=center>4 ms</div></td><td><a target=_self href=showsource.php?id=138796>C</a></td><td class='desktop-only item '>765 bytes</td><td>2024-11-30 19:49:55</td></tr>
<tr><td class='desktop-only item '>138712</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1212'>A</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=5></span><a href=reinfo.php?sid=138712 class='label label-danger' title='答案基本正确，但是格式不对。'>格式错误 得分0</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>5 ms</div></td><td><a target=_self href=showsource.php?id=138712>C</a></td><td class='desktop-only item '>622 bytes</td><td>2024-11-30 18:12:44</td></tr>
<tr><td class='desktop-only item '>138702</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1212'>A</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=4></span><a href=reinfo.php?sid=138702 class='label label-success' title='答案正确，请再接再厉。'>正确</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>5 ms</div></td><td><a target=_self href=showsource.php?id=138702>C</a></td><td class='desktop-only item '>766 bytes</td><td>2024-11-30 18:07:28</td></tr>
<tr><td class='desktop-only item '>138685</td><td><a href='contestrank.php?cid=1013&user_id=202405566811#202405566811'>202405566811</a></td><td>尹麒理</td><td><div class=center><a href='problem.php?id=1212'>A</a></div></td><td class='td_result'><span class='hidden' style='display:none' result=6></span><a href=reinfo.php?sid=138685 class='label label-danger' title='答案不对，仅仅通过样例数据的测试并不一定是正确答案，一定还有你没想到的地方，点击查看系统可能提供的对比信息。'>答案错误 得分0</a></td><td><div id=center>1236 KiB</div></td><td><div id=center>4 ms</div></td><td><a target=_self href=showsource.php?id=138685>C</a></td><td class='desktop-only item '>657 bytes</td><td>2024-11-30 17:57:10</td></tr>

"""

# 使用BeautifulSoup解析HTML
soup = BeautifulSoup(html_data, 'html.parser')

# 找到所有的<tr>标签
rows = soup.find_all('tr')

# 定义要提取的字段
fields = [
    "代码ID",
    "学号",
    "姓名",
    "题目ID",
    "结果",
    "时间"
]

# 遍历每一行并提取数据
for i, row in enumerate(rows):
    # 跳过空行
    if not row.find_all('td'):
        continue

    # 提取单元格中的数据
    cells = row.find_all('td')

    # 提取每个字段的值
    submission_id = cells[0].get_text(strip=True)
    user_id = cells[1].a.get_text(strip=True)
    name = cells[2].get_text(strip=True)
    # 修改题目ID的提取方式
    problem_id = cells[3].a['href'].split('=')[-1]  # 从href属性中提取id值
    result = cells[4].a.get_text(strip=True)
    time = cells[9].get_text(strip=True)

    # 打印结果
    print(f"记录 {i + 1}:")
    print(f"代码ID: {submission_id}")
    print(f"学号: {user_id}")
    print(f"姓名: {name}")
    print(f"题目ID: {problem_id}")
    print(f"结果: {result}")
    print(f"时间: {time}")
    print("-" * 50)